#ifndef PAPVIEW_HPP
#define PAPVIEW_HPP

#include <QDockWidget>
#include <QListIterator>

#include "command.hpp"
#include "pix.hpp"
#include "programmanagement.hpp"
#include "arrow.hpp"
#include "diagramscene.hpp"

class Pix;

namespace Ui {
    class PapView;
}

/**
* @brief
*
* @class PapView papview.hpp "papview.hpp"
*/
class PapView : public QDockWidget {
    Q_OBJECT
public:
    /**
    * @brief Constructor for PapView
    *
    * @fn PapView(Pix *pix, QWidget *parent = 0)
    * @param pix
    * @param parent
    */
    PapView(Pix *pix, QWidget *parent = 0);

    /**
    * @brief Destructor for PapView
    *
    * @fn ~PapView()
    */
    ~PapView();

    /**
    * @brief Creates a Pap of the commands in the ProgramManagement
    *
    * @fn void createPap()
    */
    void createPap();

    /**
    * @brief Highlights the command at the given address
    *
    * @fn void highlightCommand(int address)
    * @param address
    */
    void highlightCommand(int address);

    /**
    * @brief Unhighlights the command at the given address
    *
    * @fn void unhighlightCommand(int address)
    * @param address
    */
    void unhighlightCommand(int address);

    /**
    * @brief Resets the PapView
    *
    * @fn void reset()
    */
    void reset();

protected:
    /**
    * @brief Action on ChangeEvent
    *
    * @fn void changeEvent(QEvent *e)
    * @param e
    */
    void changeEvent(QEvent *e);

private:
    Ui::PapView *ui;
    Pix *pix;
    DiagramScene *diagramScene;
    QMap<int, DiagramItem*> diagramItems;
    QMap<int, QList<Command> *> commandMap;
    QMap<int, DiagramItem*> labels;
    int highlightedAddress;
    QList<DiagramItem*> nextAdresses;

private slots:
    /**
    * @brief Scales the DiagramScene after the index of the combobox has changed
    *
    * @fn void on_papScale_currentIndexChanged(int index)
    * @param index
    */
    void on_papScale_currentIndexChanged(int index);

public slots:
    /**
    * @brief Unhighlights the last highlighted address and highlights the given address
    *
    * @fn void onProgramCounterChanged(int programCounter)
    * @param programCounter
    */
    void onProgramCounterChanged(int programCounter);
};

#endif // PAPVIEW_HPP
